function plugin (Vue) {
  if (!plugin.installed) {
    Object.defineProperties(Vue.prototype, {
      hasPermissions: {
        get () {
          const me = this
          return (...args) => {
            const matchedRoutes = me.$route.matched.concat()
            let lastRoute = null
            while (true) {
              if (matchedRoutes.length > 0) {
                lastRoute = matchedRoutes.pop()
              }
              if (lastRoute.meta.type != '3') {
                break
              }
            }
            return lastRoute.meta.authorize?.some(i => {
              return args.includes(i)
            })
          }
        }
      },
      hasPermission: {
        get () {
          const me = this
          return (permissionName) => {
            const matchedRoutes = me.$route.matched.concat()
            let lastRoute = null
            while (true) {
              if (matchedRoutes.length > 0) {
                lastRoute = matchedRoutes.pop()
              }
              if (lastRoute.meta.type != '3') {
                break
              }
            }
            return lastRoute.meta.authorize?.includes(permissionName)
          }
        }
      }
    })
  }
}

export default plugin
